package com.spring.application;

import com.java.bean.Book;
import com.java.bean.Coffie;
import com.java.bean.Person;
import com.java.factory.CoffieStaticFactory;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringIOCConfApp_03 {
    /*静态工厂*/
    @Test
    public void getBeanContextByFactory() {
        ApplicationContext context = new ClassPathXmlApplicationContext("springIOC-conf-03.xml");
        CoffieStaticFactory coffieFactory = context.getBean("coffieFactory", CoffieStaticFactory.class);
        System.out.println(coffieFactory);
    }

    /*实例工厂*/
    @Test
    public void getBeanInstanceFactory(){
        ApplicationContext context = new ClassPathXmlApplicationContext("springIOC-conf-03.xml");
        Coffie coffie = context.getBean("coffie", Coffie.class);
        System.out.println(coffie);
    }

    /*携带声明周期的Bean*/
    @Test
    public void aroundBean(){
        ApplicationContext context = new ClassPathXmlApplicationContext("springIOC-conf-03.xml");
/*        Book book = context.getBean("book", Book.class);
        System.out.println(book);
        ((ClassPathXmlApplicationContext) context).destroy();*/
    }

}
